﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class admin_ProductAdd : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            if (Session["admin"] == null)
            {
                Page.ClientScript.RegisterStartupScript(this.GetType(), "", "parent.location.href='Login.aspx'", true);

            }
            else
            {
                ///绑定商品类型
                DbAccess db = new DbAccess();
                string sql = "select * from Category";
                DataSet dsCat = db.GetDataSet(sql);
                Category.DataSource = dsCat.Tables[0].DefaultView;
                Category.DataTextField = "Category";
                Category.DataValueField = "id";
                Category.DataBind();
            
            }

        }
    }
    protected void btnAdd_Click(object sender, EventArgs e)
    {
        try
        {
            string pName = ProName.Text;//商品名称
            string pCat = Category.SelectedValue;//商品分类
            string pMar = MarketPrice.Text;//市场价格
            string pMem = MemberPrice.Text;//会员价格
            string isHot = Hot.SelectedValue;//是否热卖
            string isSale = Tejia.SelectedValue;//是否特价
            string isFal = Jipin.SelectedValue;//是否推荐
            string pic = Upfile1.getpath();//图片名称
            string content = FreeTextBox1.Text;//商品介绍
            string proNum = tblNum.Text; //商品数量
            if (proNum == null)
                proNum = "0";
            string sql = "insert into product values('" + pName + "','" + content + "'," + isHot + "," + isSale + "," + isFal + ",'" + pic + "'," + pMem + "," + pMar + "," + pCat + ",'" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "',"+proNum+")";
            DbAccess db = new DbAccess();
            if (db.ExecuteSql(sql))
            {
                cleTxt();
                Page.ClientScript.RegisterStartupScript(this.GetType(), "", "alert('添加成功')", true);


            }
            else
            {
                Page.ClientScript.RegisterStartupScript(this.GetType(), "", "alert('添加失败')", true);

            
            }

        }
        catch
        { 
        
        }
    }
    protected void btnClear_Click(object sender, EventArgs e)
    {
        cleTxt();
    }
    public void cleTxt()//清空
    {
        ProName.Text = "";
        MarketPrice.Text = "";
        MemberPrice.Text = "";
        FreeTextBox1.Text = "";
        Upfile1.setPic();
    
    }
}
